package com.study.demo4;

import java.util.Objects;

public class StudentLearning implements Comparable<StudentLearning> {
    private String name;
    private int age;
    private int Chinese;
    private int maths;
    private int english;
    
    public StudentLearning() {
    }
    
    public StudentLearning(String name, int age, int Chinese, int maths, int english) {
        this.name = name;
        this.age = age;
        this.Chinese = Chinese;
        this.maths = maths;
        this.english = english;
    }
    
    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }
    
    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }
    
    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }
    
    /**
     * 获取
     *
     * @return Chinese
     */
    public int getChinese() {
        return Chinese;
    }
    
    /**
     * 设置
     *
     * @param Chinese
     */
    public void setChinese(int Chinese) {
        this.Chinese = Chinese;
    }
    
    /**
     * 获取
     *
     * @return maths
     */
    public int getMaths() {
        return maths;
    }
    
    /**
     * 设置
     *
     * @param maths
     */
    public void setMaths(int maths) {
        this.maths = maths;
    }
    
    /**
     * 获取
     *
     * @return english
     */
    public int getEnglish() {
        return english;
    }
    
    /**
     * 设置
     *
     * @param english
     */
    public void setEnglish(int english) {
        this.english = english;
    }
    
    public String toString() {
        return "StudentLearning{name = " + name + ", age = " + age + ", Chinese = " + Chinese + ", maths = " + maths + ", english = " + english + "}" + "\t" + "sum = " + (Chinese + maths + english);
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StudentLearning that = (StudentLearning) o;
        return age == that.age && Chinese == that.Chinese && maths == that.maths && english == that.english && Objects.equals(name, that.name);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(name, age, Chinese, maths, english);
    }
    
    /*按总分从高到低输出到控制台
    如果总分一样，按照语文排序
    如果语文一样，按照数学排序
    如果数学一样，按照英语排序
    如果英语一样，按照年龄排序
    如果年龄一样，按照姓名字母顺序排序
    如果都一样，则为同一个学生，不存*/
    @Override
    public int compareTo(StudentLearning o) {
        int sum1 = this.getChinese() + this.getMaths() + this.getEnglish();
        int sum2 = o.getChinese() + o.getMaths() + o.getEnglish();
        int i = sum1 - sum2;
        i = i == 0 ? this.getChinese() - o.getChinese() : i;
        i = i == 0 ? this.getMaths() - o.getMaths() : i;
        i = i == 0 ? this.getEnglish() - o.getEnglish() : i;
        i = i == 0 ? this.getAge() - o.getAge() : i;
        i = i == 0 ? this.getName().compareTo(o.getName()) : i;
        return -i;
    }
}
